package com.hao.hospital.util;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.aop.Enhancer;

public class TimeUtil {
	//一天的时间戳 (秒/s) 
	public  final long ONE_DAY=1000*60*60*24l;
	
	private static TimeUtil me;

	public static TimeUtil me() {
		if (null == me) {
			me = Enhancer.enhance(TimeUtil.class);
		}
		return me;
	}

	/**
	 * 获取未来一周时间
	 */
	public JSONArray getNextWeek() {
		Date date = new Date(System.currentTimeMillis());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat weekday = new SimpleDateFormat("EEEE");
		String time, week;
		JSONArray nextWeek = new JSONArray();
		JSONObject day;
		for (int i = 1; i <= 7; i++) {
			Calendar calendar = Calendar.getInstance();
			calendar.add(Calendar.DATE, +i);
			date = calendar.getTime();
			time = sdf.format(date);
			week = weekday.format(date);
			day = new JSONObject();
			day.put("date", time);
			day.put("week", week);
			nextWeek.add(day);
		}
		return nextWeek;
	}

	public String weekCNtoEN(String week) {
		switch (week) {
		case "星期一":
			week = "Monday";
			break;
		case "星期二":
			week = "Tuesday";
			break;
		case "星期三":
			week = "Wednesday";
			break;
		case "星期四":
			week = "Thursday";
			break;
		case "星期五":
			week = "Friday";
			break;
		case "星期六":
			week = "Saturday";
			break;
		case "星期天":
			week = "Sunday";
			break;
		default:
			break;
		}
		return week;
	}

	/**
	 * 获取当天0点时间戳
	 * 
	 * @return
	 */
	public long getDayBeginTimestamp() {
		Date date = new Date();
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(date);
		Date date2 = new Date(date.getTime() - gc.get(gc.HOUR_OF_DAY) * 60 * 60 * 1000 - gc.get(gc.MINUTE) * 60 * 1000
				- gc.get(gc.SECOND) * 1000);
		return date2.getTime();
	}

	// 时间戳转时间
	public String stampToDate(String s) {
		String res;
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd EEEE");
		long lt = new Long(s);
		Date date = new Date(lt);
		res = simpleDateFormat.format(date);
		return res;
	}

	// 时间转时间戳
	public Long dateToStamp(String s) throws ParseException {
		String res;
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = simpleDateFormat.parse(s);
		long ts = date.getTime();
		return ts;
	}

	public String stampToDateInYear(String s) {
		String res;
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd  EEEE");
		long lt = new Long(s);
		Date date = new Date(lt);
		res = simpleDateFormat.format(date);
		return res;
	}
	public String stampToDateInYearNoWeek(String s) {
		String res;
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		long lt = new Long(s);
		Date date = new Date(lt);
		res = simpleDateFormat.format(date);
		return res;
	}

	public static void main(String[] args) {
		System.out.println(TimeUtil.me().getDayBeginTimestamp());
	}

}
